package com.edu.oracle.Controller;

import com.edu.oracle.pojo.Student1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String sno = request.getParameter("name");
        String password = request.getParameter("password");

        Student1 student1= new Student1();

        student1.setSclass(password);
        student1.setSno(sno);
        student1.setSname("李四");
        HttpSession session = request.getSession(true);
        session.setAttribute("student1",student1);

        request.getRequestDispatcher("index.jsp").forward(request,response);
       /* Connection conn = null;
        PreparedStatement pstm = null;
        ResultSet rs = null;
        String url="jdbc:oracle:thin:@localhost:1521:orcl";
        String user="scott";
        String pass="oracle";

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            conn= DriverManager.getConnection(url,user,pass);
            pstm=conn.prepareStatement("select * from student where sno=? and sclass=?");
            pstm.setString(1,sno);
            pstm.setString(2,password);
            rs=pstm.executeQuery();
            if(rs.next()){
                Student stu =new Student();
                stu.setSname(rs.getString("sname"));
                System.out.println(rs.getString("sname"));
                System.out.println("登录成功");
                request.getRequestDispatcher("index.jsp").forward(request,response);
                // response.sendRedirect("index.jsp");
            }else {
                System.out.println("登录失败");

                request.getRequestDispatcher("login.jsp").forward(request,response);
            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            try {
                rs.close();
                pstm.close();
                conn.close();
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
        }*/



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
